package com.xywy.tangandroid.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.xywy.tangandroid.bean.User;

public class UserKeeper {
	static User user;
	public static void saveUserInfo(User user,Context context){
		SharedPreferences sp = context.getSharedPreferences("xywy_tang_user", Context.MODE_PRIVATE);
		Editor editor = sp.edit();
	    editor.putString("userid", user.getUserid());
		editor.putString("birthday", user.getBirthday());
		editor.putString("accountstr", user.getAccountstr());
		editor.putString("isregister", user.getIsregister());
//		editor.putString("phonenum", user.getPhonenum());
		editor.putString("phonenum", user.getPhonenum());
		editor.putInt("height", user.getHeight());
		editor.putString("sex", user.getSex());
		editor.putInt("state", user.getState());
		editor.commit();
	}
	
	public static User getCurrentUser(Context context){
		user = User.getIUserInstance(context);
		if(user != null && user.getUserid() != null){
			return user;
		}else {
			SharedPreferences sp = context.getSharedPreferences("xywy_tang_user", Context.MODE_PRIVATE);
		    if(sp.contains("userid")){
		    	user.setAccountstr(sp.getString("accountstr", ""));
		    	user.setBirthday(sp.getString("birthday", ""));
		    	user.setHeight(sp.getInt("height", 0));
		    	user.setIsregister(sp.getString("isregister", ""));
		    	user.setPhonenum(sp.getString("phonenum", ""));
		    	user.setSex(sp.getString("sex", ""));
		    	user.setState(sp.getInt("state", 0));
		    	user.setUserid(sp.getString("userid", ""));
		    	return user;
		    }else {
				return user;
			}
		}
	}
}
